//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_mobrespavailable.sqf"
#include "xr_macros.sqf"

private ["_num", "_mrrname", "_mrnumstr", "_mrtext", "_mrvec", "_depl", "_enear"];
PARAMS_1(_num);

_mrrname = d_mob_respawns select (_num - 1);

_mrnumstr = switch (_num) do {
	case 1: {"one"};
	case 2: {"two"};
	case 3: {"three"};
	case 4: {"four"};
	case 5: {"five"};
	case 6: {"six"};
};

_mr_available = true;
_mrtext = "";
_mrvec = missionNamespace getVariable [_mrrname, objNull];
if (isNull _mrvec) exitWith {
	[false, ""]
};

_isinair = _mrvec getVariable ["d_in_air", false];
switch (true) do {
	case (_isinair): {
		_mrtext = format [(localize "STR_DOM_MISSIONSTRING_925"), _mrnumstr];
		_mr_available = false;
	};
	case (speed _mrvec > 4): {
		_mrtext = format [(localize "STR_DOM_MISSIONSTRING_926"), _mrnumstr];
		_mr_available = false;
	};
	case (surfaceIsWater [(position _mrvec) select 0,(position _mrvec) select 1]): {
		_mrtext = format [(localize "STR_DOM_MISSIONSTRING_927"), _mrnumstr];
		_mr_available = false;
	};
	case (!alive _mrvec): {
		_mrtext = format [(localize "STR_DOM_MISSIONSTRING_928"), _mrnumstr];
		_mr_available = false;
	};
	default {
		_depl = __GV(_mrvec,d_MHQ_Deployed);
		if (isNil "_depl" || {!_depl}) then {
			_mrtext = format [(localize "STR_DOM_MISSIONSTRING_929"), _mrnumstr];
			_mr_available = false;
		} else {
			_enear = __GV(_mrvec,d_enemy_near);
			if (!isNil "_enear" && {_enear}) then {
				_mrtext = format [(localize "STR_DOM_MISSIONSTRING_930"), _mrnumstr];
				_mr_available = false;
			};
		};
	};
};
[_mr_available, _mrtext]